package com.designpattern.SimpleFactoryPattern;

/**
 * @Author yp
 * @Date 2021-05-24
 * @Description 简单工厂
 **/

public class SampleFactory {

    /**
     * 简单工厂
     */
//    public static Person makePerson(String type){
//        if (type.equals("man")){
//            Person man = new Man();
//            return man;
//        }else if (type.equals("woman")){
//            Person women = new Women();
//            return women;
//        }else {
//            System.out.println("生产失败！");
//            return null;
//        }
//
//    }

    /**
     * 简单工厂放射实现(推荐)
     */
    public static Person makePerson(Class c){
        Person person = null;
        try {
            person = (Person) Class.forName(c.getName()).newInstance();
        }catch (Exception err){
            System.out.println("类不存在");
            System.out.println(err.getMessage());
        }
        return person;
    }


}
